<?php
/**
 * This file is form http://findcat.cn
 *
 * @link     https://findcat.cn
 * @email    1476982312@qq.com
 */
namespace Database\Seeder;

use Encore\Admin\Auth\Database\Permission;

/**
 * 生成权限的seeder基础方法.
 *
 * Trait SeederMaker
 */
trait PermissionSeederMaker
{
    /**
     * 创建权限.
     *
     * @param $name
     * @param $slug
     * @param $httpMethod
     * @param $httpPath
     *
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
     */
    public function createPermissions($name, $slug, $httpMethod, $httpPath)
    {
        return Permission::query()->updateOrCreate(
            [
                'slug'         => $slug,
                'name'         => $name,
            ],
            [
                'http_method'  => $httpMethod,
                'http_path'    => $httpPath,
            ]
        );
    }
}
